
set(CMSIS_DIR ${CMAKE_SOURCE_DIR}/thirdparty/cmsis)

get_filename_component(CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(driver_name driv_${CURRENT_DIR_NAME})

#n32g45x_hal
set(N32_HAL_DIR ${CMAKE_SOURCE_DIR}/thirdparty/n32g45x_hal)
set(N32G45X_HAL_SRCS
    ${N32_HAL_DIR}/src/misc.c
    ${N32_HAL_DIR}/src/n32g45x_adc.c
    ${N32_HAL_DIR}/src/n32g45x_bkp.c
    ${N32_HAL_DIR}/src/n32g45x_can.c
    ${N32_HAL_DIR}/src/n32g45x_comp.c
    ${N32_HAL_DIR}/src/n32g45x_crc.c
    ${N32_HAL_DIR}/src/n32g45x_dac.c
    ${N32_HAL_DIR}/src/n32g45x_dbg.c
    ${N32_HAL_DIR}/src/n32g45x_dma.c
    ${N32_HAL_DIR}/src/n32g45x_dvp.c
    ${N32_HAL_DIR}/src/n32g45x_eth.c
    ${N32_HAL_DIR}/src/n32g45x_exti.c
    ${N32_HAL_DIR}/src/n32g45x_flash.c
    ${N32_HAL_DIR}/src/n32g45x_gpio.c
    ${N32_HAL_DIR}/src/n32g45x_i2c.c
    ${N32_HAL_DIR}/src/n32g45x_iwdg.c
    ${N32_HAL_DIR}/src/n32g45x_opamp.c
    ${N32_HAL_DIR}/src/n32g45x_pwr.c
    ${N32_HAL_DIR}/src/n32g45x_qspi.c
    ${N32_HAL_DIR}/src/n32g45x_rcc.c
    ${N32_HAL_DIR}/src/n32g45x_rtc.c
    ${N32_HAL_DIR}/src/n32g45x_sdio.c
    ${N32_HAL_DIR}/src/n32g45x_spi.c
    ${N32_HAL_DIR}/src/n32g45x_tim.c
    ${N32_HAL_DIR}/src/n32g45x_tsc.c
    ${N32_HAL_DIR}/src/n32g45x_usart.c
    ${N32_HAL_DIR}/src/n32g45x_wwdg.c
    ${N32_HAL_DIR}/src/system_n32g45x.c
)

file(GLOB_RECURSE  BOARD_DRIV_SRCS src/*.c src/*_gcc.s)

add_library(${driver_name} STATIC
    ${N32G45X_HAL_SRCS}
    ${BOARD_DRIV_SRCS}
)
target_include_directories(${driver_name}
    PRIVATE
        ${N32_HAL_DIR}/inc
        ${CMSIS_DIR}
        src
    PUBLIC
        ..
)

string(TOUPPER ${CURRENT_DIR_NAME} BOARD_NAME_UPPER)

target_compile_definitions(${driver_name}
    PRIVATE
        USE_HAL_DRIVER
        N32G45X
        $<$<CONFIG:Debug>:USE_FULL_ASSERT>
    PUBLIC
        EV_BOARD_${BOARD_NAME_UPPER}=1
)

target_compile_options(${driver_name} PRIVATE
    -Wno-unused-parameter
)
